/*
 * @desc:
 * @LastEditTime: 2022-10-27 09:35:33
 * @params:
 * @return::
 */
import { defineStore, createPinia } from 'pinia'
// import piniaPersistConfig from "@/config/piniaPersist";
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import piniaPersistConfig from '../config/piniaPersist'
import { Names } from './store-namespace'
import { globalState } from './interface'

export const useGlobalStore = defineStore(Names.Global, {
  state: (): globalState => {
    return {
      token: '',
      indexContentList: [],
      ifLogout: false,
    }
  },
  //类似于computed 可以帮我们去修饰我们的值
  getters: {},
  //可以操作异步 和 同步提交state
  actions: {
    // setToken
    setToken(token: string) {
      this.token = token
    },
  },
  // persist: piniaPersistConfig(Names.Global),
  persist: true,
})

// piniaPersist(持久化)
const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)

export default pinia
